<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        /*  去除数组中所有重复的元素
           原数组:var arr = ['a','b','a','c','haha','a','d','d','c','f','hello','hello']
         处理后的数组应该为['a','b','c','haha','d','f','hello'] */

        var arr = ['a', 'b', 'a', 'c', 'haha', 'a', 'd', 'd', 'c', 'f', 'hello', 'hello'];
        /* function str(arr) {
            for (var i = 0; i < arr.length; i++) {
                for (var j = i + 1; j < arr.length; j++) {
                    if (arr[i] == arr[j]) {
                        arr.splice(j, 1);
                        j--;
                    }
                }
            }
            return arr;
        }
        console.log(str(arr)); */
        var str = [];
        for (var i = 0; i < arr.length; i++) {
            var cc = true;
            for (var j = 0; j < str.length; j++) {
                if (arr[i] == str[j]) {
                    cc = false;
                    break;
                }

            }
            if (cc) {
                str[str.length] = arr[i];
            }
        } console.log(str);

    </script>
</head>

<body>

</body>

</html>